<template>
	<view>
		<view class="boxes-title">
			<view>工单编号:</view>
			<view>{{ orderName }}</view>
		</view>

		<view class="boxes">
			<view class="title">处理类别:</view>
			<picker @change="popupChange1" :value="index1" :range="array1" range-key="name">
				<view v-if="statu1">{{ codeName }}</view>
				<view v-else>{{ array1[index1].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes2">
			<view class="title">处理内容:</view>
			<picker @change="popupChange2" :value="index2" :range="array2" range-key="name">
				<view v-if="statu2">{{ codeName }}</view>
				<view v-else>{{ array2[index2].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes">
			<view class="title">解决措施:</view>
			<picker @change="popupChange3" :value="index3" :range="array3" range-key="name">
				<view v-if="statu3">{{ codeName }}</view>
				<view v-else>{{ array3[index3].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes2">
			<view class="title">故障内容:</view>
			<picker @change="popupChange4" :value="index4" :range="array4" range-key="name">
				<view v-if="statu4">{{ codeName }}</view>
				<view v-else>{{ array4[index4].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes">
			<view class="title">处理结果:</view>
			<picker @change="popupChange5" :value="index5" :range="array5" range-key="name">
				<view v-if="statu5">{{ codeName }}</view>
				<view v-else>{{ array5[index5].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes2">
			<view class="title">归属类别:</view>
			<picker @change="popupChange6" :value="index6" :range="array6" range-key="name">
				<view v-if="statu6">{{ codeName }}</view>
				<view v-else>{{ array6[index6].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes">
			<view class="title">大/小修:</view>
			<picker @change="popupChange7" :value="index7" :range="array7" range-key="name">
				<view v-if="statu7">{{ codeName }}</view>
				<view v-else>{{ array7[index7].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes2">
			<view class="title">表管阀:</view>
			<picker @change="popupChange8" :value="index8" :range="array8" range-key="name">
				<view v-if="statu8">{{ codeName }}</view>
				<view v-else>{{ array8[index8].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes">
			<view class="title">口径:</view>
			<picker @change="popupChange9" :value="index9" :range="array9" range-key="name">
				<view v-if="statu9">{{ codeName }}</view>
				<view v-else>{{ array9[index9].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes2">
			<view class="title">责任划分:</view>
			<picker @change="popupChange10" :value="index10" :range="array10" range-key="name">
				<view v-if="statu10">{{ codeName }}</view>
				<view v-else>{{ array10[index10].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes">  
			<view class="title">材质:</view>
			<picker @change="popupChange11" :value="index11" :range="array11" range-key="name">
				<view v-if="statu11">{{ codeName }}</view>
				<view v-else>{{ array11[index11].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>

		<view class="boxes2">
			<view class="title">处理人员:</view>
			<input type="text" v-model="name" placeholder="请输入" />
		</view>
		<view class="boxes">
			<view class="title">电话:</view>
			<input type="number" v-model="phone" placeholder="请输入" />
		</view>
		<view class="boxes2">
			<view class="title">是否止水:</view>
			<picker @change="popupChange12" :value="index12" :range="array12" range-key="name">
				<view>{{ array12[index12].name }}</view>
			</picker>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>
		<view class="boxes" v-if="statu12" @click="toggleTab">
			<view class="title">止水时间:</view>
			<view class="picker">{{ resultInfo.result }}</view>
			<image class="uni-img-icon" src="../../static/imgs/a.png" mode=""></image>
		</view>
		<w-picker
			mode="dateTime"
			startYear="1949"
			endYear="2200"
			step="1"
			:defaultVal="defaultVal"
			:current="false"
			@confirm="onConfirm"
			ref="dateTime"
			themeColor="#f00"
		></w-picker>

		<view class="boxes-title"><view>现场照片:</view></view>
		<view class="imgBoexs">
			<image @click="upImgInfo(1)" class="uni-img" :src="sceneImg1" mode=""></image>
			<image @click="upImgInfo(2)" v-if="sceneImg1 && sceneImg1!='../../static/img/a1.png'" class="uni-img" :src="sceneImg2" mode=""></image>
			<image @click="upImgInfo(3)" v-if="sceneImg2 && sceneImg2!='../../static/img/a1.png'" class="uni-img" :src="sceneImg3" mode=""></image>
			<image @click="upImgInfo(4)" v-if="sceneImg3 && sceneImg3!='../../static/img/a1.png'" class="uni-img" :src="sceneImg4" mode=""></image>
			<image @click="upImgInfo(5)" v-if="sceneImg4 && sceneImg4!='../../static/img/a1.png'" class="uni-img" :src="sceneImg5" mode=""></image>
			<image @click="upImgInfo(6)" v-if="sceneImg5 && sceneImg5!='../../static/img/a1.png'" class="uni-img" :src="sceneImg6" mode=""></image>
		</view>

		<view class="boxes-title"><view>录音:</view></view>

		<view v-if="myvideo==''" class="uni-btn">
			<button @tap="begin">{{ stuName }}</button>
			<button @tap="stop">停止</button>
			<button @tap="play">播放</button>
			<button @tap="transmit">上传</button>
		</view>
		<view v-else class="uni-btn">
			<button @tap="play">录音文件</button>
			<button @tap="again">重新上传</button>
		</view>

		<!-- 不使用jssdk 上传录音文件 -->
		<!-- <view class="text-area" ref="input"></view> -->

		<view class="boxes-title"><view>意见:</view></view>
		<view class="nav"><textarea maxlength="-1" value="" placeholder="请输入处理意见" v-model="remark" /></view>

		<view class="uni-box"><view class="turn-up" @click="submit()">完成</view></view>
	</view>
</template>

<script>
var jweixin = require('../../components/jweixin-module/index.js'); //引用微信jssdk
export default {
	data() {
		return {
			orderID: '',
			orderName: '', //工单编号

			name: '',
			phone: '',

			codeName: '请选择', //五个类别通用

			// 处理类别
			index1: 0,
			array1: [{ code: '', name: '' }],
			code1: '', //类别code
			statu1: true,

			// 处理内容
			index2: 0,
			array2: [{ code: '', name: '' }],
			code2: '', //内容code
			statu2: true,

			// 解决措施
			index3: 0,
			array3: [{ code: '', name: '' }],
			code3: '', //措施code
			statu3: true,

			// 故障内容
			index4: 0,
			array4: [{ code: '', name: '' }],
			code4: '', //故障code
			statu4: true,

			// 处理结果
			index5: 0,
			array5: [{ code: '', name: '' }],
			code5: '', //结果code
			statu5: true,
			// 归属类别
			index6: 0,
			array6: [{ code: '', name: '' }],
			code6: '', //结果code
			statu6: true,
			// 大小修
			index7: 0,
			array7: [{ code: '', name: '' }],
			code7: '', //结果code
			statu7: true,
			// 表管阀
			index8: 0,
			array8: [{ code: '', name: '' }],
			code8: '', //结果code
			statu8: true,
			// 口径
			index9: 0,
			array9: [{ code: '', name: '' }],
			code9: '', //结果code
			statu9: true,
			// 责任划分
			index10: 0,
			array10: [{ code: '', name: '' }],
			code10: '', //结果code
			statu10: true,
			// 材质
			index11: 0,
			array11: [{ code: '', name: '' }],
			code11: '', //结果code
			statu11: true,
			// 是否止水
			index12: 0,
			array12:[{ code: '1', name: '是' },{ code: '2', name: '否' }],
			code12: 1, //结果code
			statu12: true,
			// 止水时间
			stopTime:'',
			// 延期时间
			defaultVal: [0, 0, 0, 0, 0, 0],
			mode: 'dateTime',
			// name:'日期时间选择',
			tabIndex: 0,
			resultInfo: {
				result: '请选择'
			},

			sceneImg1: '../../static/img/a1.png', //现场图片
			sceneImg2: '../../static/img/a1.png', //现场图片
			sceneImg3: '../../static/img/a1.png', //现场图片
			sceneImg4: '../../static/img/a1.png', //现场图片
			sceneImg5: '../../static/img/a1.png', //现场图片
			sceneImg6: '../../static/img/a1.png', //现场图片
			imgid1: '', //图片上传返回的id
			imgid2: '', //图片上传返回的id
			imgid3: '', //图片上传返回的id
			imgid4: '', //图片上传返回的id
			imgid5: '', //图片上传返回的id
			imgid6: '', //图片上传返回的id
			
			myvideo: '', //录音文件上传id
			remark: '', //备注

			localId: '', //录音文件id

			stuName: '录音'
		};
	},

	onShow() {
		this.getNowFormatDate()
		this.message();
		this.type(); //处理类别
		this.result(1); //处理结果
		this.result(2); //处理结果
		this.result(3); //处理结果
		this.result(4); //处理结果
		this.result(5); //处理结果
		this.result(6); //处理结果
		this.result(7); //材质
	},

	onLoad(e) {
		this.orderID = e.id;
		this.orderName = e.orderName;
	},
	
	mounted() {
		// 不使用jssdk 上传录音文件
		// var that = this;
		// var input = document.createElement('input');
		// input.id = 'uploadInput';
		// input.type = 'file';
		// input.onchange = function(e) {
		// 	var filereader = new FileReader();
		// 	// var fileType = this.files[0].type;
		// 	// console.log(fileType)
		// 	filereader.readAsDataURL(this.files[0]);
		// 	filereader.onload = function() {
		// 		// console.log(this.result);
		// 		that.upload();
		// 	};
		// };
		// that.$refs.input.$el.appendChild(input);
	},
	methods: {
		// 当前日期
		getNowFormatDate() {
			var that = this;
			var date = new Date();
			var seperator1 = '-';
			var year = date.getFullYear();
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = '0' + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = '0' + strDate;
			}
			// 出生年月日中的结束年份
			that.endYear = year;
			// console.log(that.endYear);
			year = year - 1949;
			that.defaultVal = [year, month - 1, strDate - 1];
		},
		// jssdk录音
		initAudio() {
			uni.request({
				url: '/app/wechatApi/getWxJsSdk',
				method: 'GET',
				data: {
					url: encodeURIComponent(location.href)
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						this.stuName = '录音中';
						console.log(res.data.data.appId)
						jweixin.config({
							debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
							appId: res.data.data.appId, // 必填，公众号的唯一标识
							timestamp: res.data.data.timestamp, // 必填，生成签名的时间戳
							nonceStr: res.data.data.nonceStr, // 必填，生成签名的随机串
							signature: res.data.data.signature, // 必填，签名，见附录1
							jsApiList: [
								'startRecord',
								'stopRecord',
								'onVoiceRecordEnd',
								'playVoice',
								'pauseVoice',
								'stopVoice',
								'onVoicePlayEnd',
								'uploadVoice',
								'downloadVoice',
								'translateVoice',
								'updateAppMessageShareData'
							]
						});

						jweixin.ready(function() {
							jweixin.startRecord();
						});

						jweixin.onVoicePlayEnd({
							success: function(res) {
								this.localId = res.localId;
								console.log('语音播放完毕----》', this.localId);
								// alert(this.localId, '录音地址');
							}
						});
						jweixin.error(function(res) {
							alert('error,---->', res);
							// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
						});
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		},
		begin() {
			this.initAudio();
		},
		stop() {
			let that = this;
			jweixin.stopRecord({
				success: function(res) {
					console.log('停止录音成功--->', res);
					that.stuName = '录音';
					var localId = res.localId;
					that.localId = localId;
					// alert(that.localId, '停止录音返回地址');
				}
			});
		},
		// 播放录音
		play() {
			let that = this;
			if (that.stuName=='录音中') {
				uni.showToast({
					title: '录音暂未停止!',
					icon: 'none',
					duration: 1500
				});
				return;
			}
			if (!that.localId) {
				uni.showToast({
					title: '暂未录音!',
					icon: 'none',
					duration: 1500
				});
				return;
			}
			jweixin.ready(function() {
				console.log(that.localId);
				jweixin.playVoice({
					localId: that.localId // 需要播放的音频的本地ID，由stopRecord接口获得
				});
			});
		},
		// 开始上传ss
		transmit() {
			var that = this
			if (that.stuName=='录音中') {
				uni.showToast({
					title: '录音暂未停止!',
					icon: 'none',
					duration: 1500
				});
				return;
			}
			if (!that.localId) {
				uni.showToast({
					title: '暂未录音!',
					icon: 'none',
					duration: 1500
				});
				return;
			}
			jweixin.uploadVoice({
				localId: that.localId, // 需要上传的音频的本地ID，由stopRecord接口获得
				isShowProgressTips: 1, // 默认为1，显示进度提示
				success: function(res) {
					var serverId = res.serverId; // 返回音频的服务器端ID
					console.log(serverId,'微信服务器上的id');
					uni.request({
						url: '/app/wechatApi/upload',
						method: 'GET',
						data: {
							mediaId: serverId
						},
						header: {
							'Content-type': 'application/x-www-form-urlencoded'
						},
						success: res => {
							if (res.data.code == 200) {
								uni.showToast({
									icon: 'none',
									title: res.data.message,
									duration:1500
								});
								that.myvideo = res.data.data.fileId
								
								console.log(that.myvideo, '111111111111111111111');
							} else {
								uni.showToast({
									title: res.data.message,
									icon: 'none'
								});
							}
						},
						error: e => {
							console.log(e);
						}
					});
				}
			});
		},
		// 重新上传
		again(){
			this.localId = ''
			this.myvideo = ''
		},
		// 获取信息
		message() {
			var that = this;
			uni.request({
				url: '/app/wechatApi/getUserByOpenId',
				method: 'POST',
				data: {
					openId: uni.getStorageSync('openid')
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						if (res.data.data.name) {
							this.name = res.data.data.name;
						}
						if (res.data.data.phone) {
							this.phone = res.data.data.phone;
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		},

		// 处理类别
		type() {
			var that = this;
			uni.request({
				url: '/app/wechatApi/getOrderProcess',
				method: 'POST',
				data: {
					code: 'resoveType'
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						that.array1 = res.data.data;
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		},

		// 三个 处理类别 处理内容  解决措施 （根据获取上一级的id，调用同一个接口）
		threeType(id, num) {
			uni.request({
				url: '/app/wechatApi/getOrderProcessSencond',
				method: 'POST',
				data: {
					code: id,
					parentCode: 'resoveType'
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						// console.log(res)
						if (num == 2) {
							this.array2 = res.data.data;
						} else if (num == 3) {
							this.array3 = res.data.data;
						} else if (num == 4) {
							this.array4 = res.data.data;
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		},
		  
		// 处理类别
		popupChange1: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index1 = e.target.value;
			this.code1 = this.array1[e.target.value].code;
			this.statu1 = false;
			if (this.code1 != '') {
				this.index2 = 0;
				this.array2 = [];
				this.code2 = '';
				this.statu2 = true;

				this.index3 = 0;
				this.array3 = [];
				this.code3 = '';
				this.statu3 = true;

				this.index4 = 0;
				this.array4 = [];
				this.code4 = '';
				this.statu4 = true;
				this.threeType(this.code1, 2);
			}
			console.log('处理类别的code===>', this.code1);
		},
		
		// 处理内容
		popupChange2: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			if (this.array2.length > 0) {
				this.index2 = e.target.value;
				this.code2 = this.array2[e.target.value].code;
				this.statu2 = false;
				if (this.code2 != '') {
					this.index3 = 0;
					this.array3 = [];
					this.code3 = '';
					this.statu3 = true;

					this.index4 = 0;
					this.array4 = [];
					this.code4 = '';
					this.statu4 = true;
					this.threeType(this.code2, 3);
				}
				console.log('处理内容的code===>', this.code2);
			}
		},
		
		// 解决措施
		popupChange3: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			if (this.array3.length > 0) {
				this.index3 = e.target.value;
				this.code3 = this.array3[e.target.value].code;
				this.statu3 = false;
				if (this.code3 != '') {
					this.index4 = 0;
					this.array4 = [];
					this.code4 = '';
					this.statu4 = true;
					this.threeType(this.code3, 4);
				}
				console.log('解决措施的code===>', this.code3);
			}
		},

		// 选择处理结果
		result(num) {
			var that = this;
			let myCode = '';
			if (num == 1) {
				myCode = 'operationResult';
			} else if (num == 2) {
				myCode = 'affiliationType';
			} else if (num == 3) {
				myCode = 'repairType';
			} else if (num == 4) {
				myCode = 'deviceType';
			} else if (num == 5) {
				myCode = 'caliber';
			} else if (num == 6) {
				myCode = 'dutyType';
			} else if (num == 7) {
				myCode = 'texture';
			}
			uni.request({
				url: '/app/wechatApi/getOrderProcess',
				method: 'POST',
				data: {
					code: myCode
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						if (num == 1) {
							that.array5 = res.data.data;
						} else if (num == 2) {
							that.array6 = res.data.data;
						} else if (num == 3) {
							that.array7 = res.data.data;
						} else if (num == 4) {
							that.array8 = res.data.data;
						} else if (num == 5) {
							that.array9 = res.data.data;
						} else if (num == 6) {
							that.array10 = res.data.data;
						} else if (num == 7) {
							that.array11 = res.data.data;
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		},

		// 故障内容
		popupChange4: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			if (this.array4.length > 0) {
				this.index4 = e.target.value;
				this.code4 = this.array4[e.target.value].code;
				this.statu4 = false;
				console.log('故障内容的code===>', this.code4);
			}
		},
		
		// 返回内容
		popupChange5: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index5 = e.target.value;
			this.code5 = this.array5[e.target.value].code;
			this.statu5 = false;
			console.log('处理结果的code===>', this.code5);
		},

		// 归属类别
		popupChange6: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index6 = e.target.value;
			this.code6 = this.array6[e.target.value].code;
			this.statu6 = false;
			console.log('处理结果的code===>', this.code6);
		},
		// 大小修
		popupChange7: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index7 = e.target.value;
			this.code7 = this.array7[e.target.value].code;
			this.statu7 = false;
			console.log('大小修的code===>', this.code7);
		},
		// 表管阀
		popupChange8: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index8 = e.target.value;
			this.code8 = this.array8[e.target.value].code;
			this.statu8 = false;
			console.log('处理结果的code===>', this.code8);
		},
		// 口径
		popupChange9: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index9 = e.target.value;
			this.code9 = this.array9[e.target.value].code;
			this.statu9 = false;
			console.log('处理结果的code===>', this.code9);
		},
		// 责任划分
		popupChange10: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index10 = e.target.value;
			this.code10 = this.array10[e.target.value].code;
			this.statu10 = false;
			console.log('处理结果的code===>', this.code10);
		},
		// 材质  
		popupChange11: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index11 = e.target.value;
			this.code11 = this.array11[e.target.value].code;
			this.statu11 = false;
			console.log('处理结果的code===>', this.code11);
		},
		// 止水时间
		popupChange12: function(e) {
			var that = this
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index12 = e.target.value;
			this.code12 = this.array12[e.target.value].code;
			if(e.target.value == 0){
				this.statu12 = true
			}else{
				this.statu12 = false
				this.resultInfo.result = '请选择'
			}
			console.log('处理结果的code===>', this.code12);
		},
		
		// 止水时间
		toggleTab() {
			this.$refs['dateTime'].show();
		},
		onConfirm(val) {
			// console.log(val);
			this.resultInfo = val;
			console.log(this.resultInfo.result);
		},

		// 上传录音文件
		// upload() {
		// 	var that = this;
		// 	uni.showLoading({
		// 		title: '上传中'
		// 	});
		// 	var xhr = new XMLHttpRequest();
		// 	xhr.open('post', '/app/system/upload');
		// 	let uploadInput = document.getElementById('uploadInput');
		// 	let data = new FormData();
		// 	data.append('file', uploadInput.files[0]);
		// 	xhr.send(data);
		// 	xhr.onreadystatechange = function() {
		// 		uni.hideLoading();
		// 		//后端接受完毕
		// 		if (xhr.readyState == 4 && xhr.status == 200) {
		// 			uni.showToast({
		// 				icon: 'none',
		// 				title: '上传成功'
		// 			});
		// 			var obj = JSON.parse(xhr.responseText);
		// 			console.log(obj);
		// 			that.myvideo = obj.data.fileId;
		// 			console.log(that.myvideo, '这是视频文件id');
		// 		}
		// 	};
		// },

		// 下面的是上传照片
		upImgInfo(num) {
			let that = this;
			uni.chooseImage({
				count: 1, //默认9
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album','camera'], //从相册选择
				success: function(res) {
					// console.log(JSON.stringify(res.tempFilePaths));
					let file = res.tempFilePaths[0];
					// 下面是临时使用的方法
					// let file = res.tempFiles[0].path;
					// console.log(file, 'imgimg');
					uni.showLoading({
						mask: false
					});
					uni.uploadFile({
						url: '/app/system/upload', //仅为示例，非真实的接口地址
						filePath: file,
						name: 'file',
						success: uploadFileRes => {
							uni.hideLoading();
							const res = JSON.parse(uploadFileRes.data);
							// console.log(res)
							uni.showToast({
								title: res.message,
								icon: 'none'
							});
							if(num == 1 && res.data.fileId){
								that.sceneImg1 = file;
								that.imgid1 = res.data.fileId;
							}else if(num == 2 && res.data.fileId){
								that.sceneImg2 = file;
								that.imgid2 = res.data.fileId;
							}else if(num == 3 && res.data.fileId){
								that.sceneImg3 = file;
								that.imgid3 = res.data.fileId;
							}else if(num == 4 && res.data.fileId){
								that.sceneImg4 = file;
								that.imgid4 = res.data.fileId;
							}else if(num == 5 && res.data.fileId){
								that.sceneImg5 = file;
								that.imgid5 = res.data.fileId;
							}else if(num == 6 && res.data.fileId){
								that.sceneImg6 = file;
								that.imgid6 = res.data.fileId;
							}
							console.log(res.data.fileId, '这是图片文件id');
						}
					});
				}
			});
		},

		// 提交
		submit() {
			if (!this.code1) {
				uni.showToast({
					title: '请选择处理类别!',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (!this.code2) {
				uni.showToast({
					title: '请选择处理内容!',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (!this.code5) {
				uni.showToast({
					title: '请选择处理结果!',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (!this.code9) {
				uni.showToast({
					title: '请选择口径!',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			// if (!this.code3) {
			// 	uni.showToast({
			// 		title: '请选择解决措施!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			// if (!this.code4) {
			// 	uni.showToast({
			// 		title: '请选择故障内容!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			
			// if (!this.code7) {
			// 	uni.showToast({
			// 		title: '请选择大/小修!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			// if (!this.code8) {
			// 	uni.showToast({
			// 		title: '请选择表管阀!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			
			// if (!this.code11) {
			// 	uni.showToast({
			// 		title: '请选择材质!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			let resultTime = ''
			if(this.code12 == 1){
				if(this.resultInfo.result == '请选择'){
					// uni.showToast({
					// 	title: '请选择止水时间!',
					// 	icon: 'none',
					// 	duration: 2000
					// });
					// return;
				}else{
					resultTime = this.resultInfo.result
				}
			}
			
			// if (!this.name) {
			// 	uni.showToast({
			// 		title: '请选择处理人员!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			
			// if (!this.phone) {
			// 	uni.showToast({
			// 		title: '请输入处理电话!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			
			// if (!this.remark) {
			// 	uni.showToast({
			// 		title: '请输入处理意见!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			
			let imgids = ''
			if (this.imgid1) {
				imgids = imgids.concat(this.imgid1);
			}
			if (this.imgid2) {
				imgids = imgids.concat(',' + this.imgid2);
			}
			if (this.imgid3) {
				imgids = imgids.concat(',' + this.imgid3);
			}
			if (this.imgid4) {
				imgids = imgids.concat(',' + this.imgid4);
			}
			if (this.imgid5) {
				imgids = imgids.concat(',' + this.imgid5);
			}
			if (this.imgid6) {
				imgids = imgids.concat(',' + this.imgid6);
			}
			
			// if (!imgids) {
			// 	uni.showToast({
			// 		title: '请上传现场图片!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			
			// if (!this.myvideo) {
			// 	uni.showToast({
			// 		title: '请录音后上传文件!',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// 	return;
			// }
			
			uni.showLoading({
				mask: false
			});
			uni.request({
				url: '/app/wechatApi/wechatOrder/handleOrder',
				method: 'POST',
				data: {
					openid: uni.getStorageSync('openid'),
					orderId: this.orderID,
					resoveType: this.code1,
					operationContent: this.code2,
					resoveFunction: this.code3,
					faultSource: this.code4,
					operationResult: this.code5,
					ascriptionType: this.code6,
					repairType: this.code7,
					deviceType: this.code8,
					caliber: this.code9,
					dutyType: this.code10,
					texture: this.code11,
					operationUserName: this.name,
					operationTel: this.phone,
					onsiteImg: imgids,
					soundFile: this.myvideo,
					operationRemark: this.remark,
					stopWater: this.code12,
					stopTime: resultTime,
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					// console.log(res)
					if (res.data.code == 200) {
						uni.hideLoading();
						uni.showToast({
							title: '操作成功!',
							icon: 'none'
						});
						setTimeout(function() {
							uni.navigateBack({
								delta: 2
							});
						}, 1000);
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		}
	}
};
</script>

<style>
page {
	background: #ffffff;
}
image {
	width: 150upx;
	height: 150upx;
}

.page-body-wrapper {
	justify-content: space-between;
	flex-grow: 1;
	margin-bottom: 300upx;
}

.page-body-time {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.time-big {
	font-size: 60upx;
	margin: 20upx;
}

.time-small {
	font-size: 30upx;
}

.page-body-buttons {
	margin-top: 60upx;
	display: flex;
	justify-content: space-around;
}

.page-body-button {
	width: 250upx;
	text-align: center;
}

.button-stop-record {
	width: 110upx;
	height: 110upx;
	border: 20upx solid #fff;
	background-color: #f55c23;
	border-radius: 130upx;
	margin: 0 auto;
}
.affirm {
	text-align: center;
	margin: 0 35upx 15upx 35upx;
	background: #09bb07;
	color: #ffffff;
	padding: 5upx 0;
	border-radius: 10upx;
}

picker {
	width: 70%;
	height: 50upx;
	padding: 10upx 15upx;
	border-radius: 15upx;
}
.picker{
	width: 70%;
	height: 50upx;
	padding: 10upx 15upx;
	border-radius: 15upx;
}

.uni-img-icon {
	width: 25upx;
	height: 25upx;
}
.boxes-title {
	display: flex;
	align-items: center;
	padding: 20upx 35upx;
	font-size: 34upx;
}
.boxes {
	display: flex;
	align-items: center;
	padding: 20upx 35upx;
	background: #8ef7c9;
	color: #000000;
	border-bottom: 1px solid #ffffff;
}
.boxes2 {
	display: flex;
	align-items: center;
	padding: 20upx 35upx;
	background: #eeeeee;
	color: #000000;
	border-bottom: 1px solid #ffffff;
}
input {
	border-radius: 10upx;
	width: 70%;
	padding: 10upx 20upx;
	font-size: 28upx;
}
.navs {
	padding: 20upx 0 0 35upx;
	border: none;
}
.title {
	font-size: 32upx;
	color: #333333;
	opacity: 0.9;
	font-weight: 500;
	width: 150upx;
}

.nav {
	background: #ffffff;
	padding: 5upx;
	margin: 0 20upx;
}
.nav textarea {
	padding: 15upx;
	font-size: 26upx;
	width: 95%;
	line-height: 150%;
	height: 200upx;
	border: 1px solid #e0e0e0;
}
.imgBoexs{
	display: flex;flex-wrap: wrap;align-content: flex-start;
	margin-left:20upx;
}
.uni-img {
	width: 30%;
	height: 200upx;
	background: #ffffff;
	margin:1%;
}
.uni-box {
	display: flex;
	justify-content: space-around;
	align-content: center;
	text-align: center;
	color: #ffffff;
	width: 100%;
	margin: 30upx 0;
}
.turn-up {
	background: #48e6e7;
	text-align: center;
	color: #ffffff;
	width: 90%;
	margin-top: 50upx;
	padding: 15upx 10upx;
	border-radius: 15upx;
}
.done {
	background: #4a98ee;
}
.postpone {
	background: #48e6e7;
}
.send {
	background: #ff5c31;
}
/* 录音 */
.text-area {
	display: flex;
	padding: 10upx 35upx;
}
button {
	font-size: 30upx;
}
</style>
